/**
 * Sequelize是一个用于Postgres、MySQL、MariaDB、SQLite和Microsoft SQL Server的基于Promise的Node.js ORM框架。
 * 它具有可靠的事务支持、关系管理、预加载和延迟加载、主从复制(Read replication)等功能。
 */
//代码链接数据库
const {Sequelize, Model} = require('sequelize')
const {
  dbName,
  host,
  port,
  user,
  password
} = require('./index').database
const sequelize = new Sequelize(dbName, user, password, {
  dialect: 'mysql',
  host,
  port,
  logging: true,
  timezone: '+08:00',
  define: {
    createdAt: 'created_at',
    updatedAt: 'updated_at',
    deletedAt: 'deleted_at',
    timestamps: true, //数据库是否包含created_at、updated_at字段 默认true
    paranoid: true,  //数据库是否包含deleted_at字段  必须是timestamps: true的时候生效 默认false
    underscored: true, //会将所有的驼峰命名改成下划线命名
    //过滤返回字段
    scopes:{
      //自定义
      cud: {
        attributes: {
          exclude: ['created_at','updated_at','deleted_at']
        }
      },
      cd: {
        attributes: {
          exclude: ['created_at','deleted_at']
        }
      }
    }
  }
})
sequelize.sync({
  force: false, //修改字段之后会响应式删除表然后同步字段、会删除表、删除表、删除
})





module.exports = {
  sequelize
}